package com.ruoyi.web.controller.mini;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.MiniLoginUser;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.MyReplier;
import com.ruoyi.system.domain.MyUser;
import com.ruoyi.system.service.IMyReplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/mini/replier")
@Api(tags = "回复人相关接口")
public class ReplierController extends BaseController {

    @Autowired
    private IMyReplierService myReplierService;
    @Autowired
    private TokenService tokenService;

    /**
     * 回复人登录
     */
    @PostMapping("/login")
    @ApiOperation("回复人登录")
    public AjaxResult login(@RequestBody Map<String, String> map){
        MyReplier replier = myReplierService.login(map);

        // 生成token
        MiniLoginUser loginUser = new MiniLoginUser();
        loginUser.setId(replier.getId());
        loginUser.setType(1);
        String token = tokenService.createToken(loginUser);

        // 返回结果
        HashMap<String, Object> res = new HashMap<>();
        res.put("token", token);
        res.put("loginUser", loginUser);
        return success(res);
    }

    /**
     * 测试
     */
    @GetMapping("/test")
    @ApiOperation("测试")
    public AjaxResult test(){
        return success("test");
    }

}
